package com.cdh.oss.controller;

import com.cdh.oss.service.OssService;
import com.cdh.utils.result.Restful;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

@RestController
@RequestMapping("ossService")
@CrossOrigin
@Slf4j
public class OssController {

    @Autowired
    private OssService ossService;

    @PostMapping("upload")
    public Restful uploadOssFile(MultipartFile file){
        //获取上传文件
        String url = ossService.uploadFileAvatar(file);
        return Restful.ok().data("url",url);
    }

    @DeleteMapping("remove")
    public Restful removeFile(@RequestBody String url){
        ossService.removeFileAvatar(url);
        return Restful.ok();
    }

}
